package com.cg.design.graphicdesignpattern.strategy;

/**
 * 使用排序策略类Sorter
 *
 * @program: LeetCode->SortAndPrint
 * @description: 使用排序策略类Sorter
 * @author: cg
 * @create: 2022-03-24 19:40
 **/
public class SortAndPrint {
    Comparable[] data;
    Sorter sorter;

    public SortAndPrint(Comparable[] data, Sorter sorter) {
        this.data = data;
        this.sorter = sorter;
    }

    public void execute() {
        System.out.print("排序前:");
        print();
        sorter.sort(data);
        System.out.print("排序后:");
        print();
    }

    public void print() {
        for (int i = 0; i < data.length; i++) {
            System.out.print(data[i] + ", ");
        }
        System.out.println("");
    }

}
